//
//  LLGStatuses.swift
//  Weibo30LLG
//
//  Created by 李龙 on 16/8/10.
//  Copyright © 2016年 lilong. All rights reserved.
//

import UIKit

//微博模型
class LLGStatuses: NSObject {
    //微博发布时间
    var created_at: String?
    //用户id
    var id: Int64 = 0
    //内容
    var text: String?
    //来源
    var source: String?
    //关注用户模型
    var user: LLGUser?

    //转发数
    var reposts_count: Int = 0
    //评论数
    var comments_count: Int = 0
    //赞数
    var attitudes_count: Int = 0
    
    //转发微博用户模型
    var retweeted_status: LLGStatuses?
    
    //配图
    var pic_urls: [LLGStatusePictureInfo]?
    
    //kvc构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    //防止崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //设置关注微博模型,字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
        
            guard let dict = value as? [String: AnyObject] else {
            
                return
            }
            
            user = LLGUser(dict: dict)
        } else if key == "retweeted_status" {
        
            guard let dict = value as? [String: AnyObject] else {
            
                return
            }
            
            retweeted_status = LLGStatuses(dict: dict)
            
        } else if key == "pic_urls" {
        
            guard let dictArray = value as? [[String: AnyObject]] else {
            
                return
            }
            
            var arrayM = [LLGStatusePictureInfo]()
            
            for dict in dictArray {
            
                let pictureInfo = LLGStatusePictureInfo(dict: dict)
                arrayM.append(pictureInfo)
            }
            
            pic_urls = arrayM
        
        } else {
        
            super.setValue(value, forKey: key)
        }
    }
    
    
    
}
